package cn.hanyx.coder.design.pattern.creational.singleton;

import java.util.concurrent.atomic.AtomicLong;

/**
 * IdDemo
 *
 * @author hanyx
 * @date 2020/07/13
 */
public class IdDemo {
    private IdDemo() {

    }

    private static class SingletonHolder {
        private static final IdDemo instance = new IdDemo() ;
    }

    private AtomicLong id = new AtomicLong(0);

    public Long getId() {
        return id.incrementAndGet();
    }

    public static IdDemo getInstance() {
        return SingletonHolder.instance;
    }

    public static void main(String[] args) {
        System.out.println(IdDemo.getInstance().getId());
    }
}
